//
// BisectionMethod.h
// Bisection method implementation.
//
// Author: Gabriel H. Barbuto (gbarbuto@dc.uba.ar)
//
#ifndef _BISECTION_METHOD_H_
#define _BISECTION_METHOD_H_

#include <cstddef>
#include <functional>
#include <vector>

#include "BinaryIterativeMethod.h"
#include "IterativeMethod.h"
#include "TP1MetNumDLL.h"

class BisectionMethod : public BinaryIterativeMethod
{
public:

	TP1METNUMDLL_API BisectionMethod(std::function<double(double)> const &f, std::size_t const &iterations);

	TP1METNUMDLL_API BisectionMethod(std::function<double(double)> const &f, double const &epsilon = IterativeMethod::default_epsilon(), std::size_t const &iterations = IterativeMethod::default_iterations());

	using BinaryIterativeMethod::operator();

	TP1METNUMDLL_API virtual double operator()(std::vector<double> const &arguments);

private:

	TP1METNUMDLL_API static inline int sign(double const &value)
	{
		return (0.0 < value) - (value < 0.0);
	}

	std::function<double(double)> const _f;
};

#endif

